package com.hnkywl.sts.action.base;

import com.hnkywl.sts.entity.base.Dxrz;
import com.hnkywl.sts.entity.sys.Yg;
import com.hnkywl.sts.service.base.DxpzService;
import com.hnkywl.sts.service.base.DxrzService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-5-20
 * Time: 下午8:51
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/base/dxrz")
public class DxrzAction extends SimpleActionSupport {
    private DxrzService dxrzService;
    private DxpzService dxpzService;
    //短信配置实例
    private Dxrz dxrz;
    //短信配置实例
    private Long dxrzId;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows = 10;
    //发送日期
    private Date fsrq;
    //测试内容
    private String testContent;
    //电话号码组
    private String dhhms;

    //短信日志的查询列表显示
    @Action("dxrzList")
    public void dxrzList() {
        this.renderJson(this.dxrzService.findDxrzList(fsrq, page, rows));
    }

    @Action("dxrz_detail")
    public String dxrzDetail() {
        if (dxrzId != null) {
            dxrz = dxrzService.findDxrzDetail(dxrzId);
        }
        return SUCCESS;
    }

    @Action("dxrz_content")
    public String dxrzContent() {
        return SUCCESS;
    }

    @Action("dxrz_test")
    public void dxrzTest() {
        try {
            List<Yg> ygs = new ArrayList<Yg>();
            String[] dhhmsz = dhhms.split(",");
            for (String dhhmd : dhhmsz) {
                Yg yg = new Yg();
                yg.setDhhm(dhhmd);
                ygs.add(yg);
            }
            this.dxpzService.sendMsgForTest(ygs, testContent);
            renderText("{\"statusCode\":\"200\", \"message\":\"短信测试成功\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    //====================get and set ===============================


    public String getTestContent() {
        return testContent;
    }

    public void setTestContent(String testContent) {
        this.testContent = testContent;
    }

    public String getDhhms() {
        return dhhms;
    }

    public void setDhhms(String dhhms) {
        this.dhhms = dhhms;
    }

    public Date getFsrq() {
        return fsrq;
    }

    public void setFsrq(Date fsrq) {
        this.fsrq = fsrq;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Dxrz getDxrz() {
        return dxrz;
    }

    public void setDxrz(Dxrz dxrz) {
        this.dxrz = dxrz;
    }

    public Long getDxrzId() {
        return dxrzId;
    }

    public void setDxrzId(Long dxrzId) {
        this.dxrzId = dxrzId;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    @Autowired
    public void setDxrzService(DxrzService dxrzService) {
        this.dxrzService = dxrzService;
    }

    @Autowired
    public void setDxpzService(DxpzService dxpzService) {
        this.dxpzService = dxpzService;
    }
}
